refactor: update to work with latest openedx_content container changes [FC-0117]#38181
refactor: update to work with latest openedx_content container changes [FC-0117]#38181bradenmacdonald wants to merge 1 commit intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @bradenmacdonald! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
1 similar comment
|
Thanks for the pull request, @bradenmacdonald! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
kdmccormick
left a comment
There was a problem hiding this comment.
Some nice cleanup 🔥
Do you mind pushing the temporary version bumps so that the sandbox builds?
| # convert "unit" -> "vertical", "subsection" -> "sequential" | ||
| block_type = content_api.get_container_type(upstream_child.container_type_code).olx_tag_name | ||
| if not block_type or block_type not in ("vertical", "sequential"): |
There was a problem hiding this comment.
| # convert "unit" -> "vertical", "subsection" -> "sequential" | |
| block_type = content_api.get_container_type(upstream_child.container_type_code).olx_tag_name | |
| if not block_type or block_type not in ("vertical", "sequential"): | |
| if upstream_child.container_type_code not in (Unit.type_code, Subsection.type_code): |
What do you think about learning towards <ContainerSubclass>.type_code as the canonical way to check type codes?
I think, in general, we could lean away from the olx tags except for when we really need them (serialization/deserialization). Especially since the ContainerKeys don't even use those olx codes.
| self.unit = library_api.create_container( | ||
| library_key=self.library.key, | ||
| container_type=library_api.ContainerType.Unit, | ||
| container_type=content_models.Unit, |
There was a problem hiding this comment.
I think that either the pararm container_type: ContainerType needs to become container_subclass: type[Container], or arg value needs to become content_models.Unit.get_container_type().
| ] | ||
|
|
||
| # For now, we only allow the following types of containers in content libraries, and their hierarchy is hard-coded. | ||
| LIBRARY_ALLOWED_CONTAINER_TYPES = ["unit", "subsection", "section"] |
There was a problem hiding this comment.
| LIBRARY_ALLOWED_CONTAINER_TYPES = ["unit", "subsection", "section"] | |
| LIBRARY_ALLOWED_CONTAINER_TYPES = [Unit.type_code, Subsection.type_code, Section.type] |
Maybe we avoid using the string names directly?
| container, _initial_version = content_api.create_container_and_version( | ||
| content_library.learning_package_id, | ||
| key=slug, | ||
| title=title, | ||
| container_type=container_type, | ||
| entities=[], | ||
| created=created, | ||
| created_by=user_id, | ||
| ) |
| """ | ||
| # Use 'source' to get this as a string, not an enum value instance which the container_type field has. | ||
| container_type_code = serializers.CharField(source="container_key.container_type") | ||
| # Deprecated - ambiguous type |
There was a problem hiding this comment.
| # Deprecated - ambiguous type | |
| # Deprecated (ambiguously named). Identical to container_type_code. |
| children = get_container_children(container_key, published=False) | ||
| child_key_name = "usage_key" if isinstance(container, Unit) else "container_key" |
There was a problem hiding this comment.
I know this is existing code, but I really dislike getattr and my experience is that others devs see its usage and replicate it because it's fewer keystrokes than the equivalent more-typesafe code.
Would you consider dropping child_key_name and changing:
object_id=str(getattr(child, child_key_name)),to
object_id=str(child.usage_key if isinstance(container, Unit) else child.container_key),?
(Tangentially, I think this code an indication that we need some shared idea of "entity_key"--not PublishableEntity.key--which encompasses both component usage keys and container keys.)
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class ContainerMetadata(PublishableItem): |
There was a problem hiding this comment.
Not an issue for this PR, but I'd love to eventually push these dataclasses down into openedx-core.
Description
Thanks to the changes in openedx/openedx-core#495 , we can simplify a lot of the container-related code in the content libraries API.
Supporting information
See openedx/openedx-core#412
Testing instructions
Ensure that content libraries are working as normal - create components and containers, use them in courses, etc.
Deadline
Verawood